"""
UI 组件基类
为所有 UI 组件提供基础功能
"""

import streamlit as st
from abc import ABC, abstractmethod
from .api_client import APIClient


class UIComponent(ABC):
    """UI 组件基类，所有 UI 组件都应继承此类"""

    def __init__(self, api_client: APIClient):
        """
        初始化 UI 组件

        Args:
            api_client: API 客户端实例
        """
        self.api_client = api_client

    @abstractmethod
    def render(self):
        """渲染 UI 组件，子类必须实现此方法"""
        pass

    def render_header(self, title: str, icon: str = ""):
        """
        渲染组件标题

        Args:
            title: 标题文本
            icon: 标题图标
        """
        st.markdown(
            f'<div class="main-header">{icon} {title}</div>', unsafe_allow_html=True
        )

    def render_card(self, content_func, width=None):
        """
        渲染卡片容器

        Args:
            content_func: 渲染卡片内容的函数
            width: 卡片宽度
        """
        st.markdown('<div class="card">', unsafe_allow_html=True)
        content_func()
        st.markdown("</div>", unsafe_allow_html=True)

    def render_info(self, title: str, content: str, expanded: bool = True):
        """
        渲染信息面板

        Args:
            title: 面板标题
            content: 面板内容
            expanded: 是否默认展开
        """
        with st.expander(title, expanded=expanded):
            st.markdown(content)
